{{- define "main" }}
{{- $channelsInfo := .Site.Data.channels.info }}
{{- $_pathElements := index ( findRESubmatch  `^modules/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/*$` $.File.Dir 1 ) 0 }}
{{- $currentModuleName := index $_pathElements 1 }}
{{- $currentModuleChannel := index $_pathElements 2 }}

{{- $d8Edition := "" }}
{{- $moduleStatus := "" }}

{{- range sort $channelsInfo "stability" "desc" }}
  {{- if eq .code "rock-solid" }}{{ continue }}{{ end }}
  {{- with $.GetPage ( printf "modules/%s/%s/README.md" $currentModuleName .code  ) }}
    {{- if and .Params.d8Edition ( not $d8Edition ) }}{{ $d8Edition = .Params.d8Edition }}{{ end }}
    {{- if and .Params.moduleStatus ( not $moduleStatus ) }}{{ $moduleStatus = .Params.moduleStatus }}{{ end }}
  {{- end}}
{{- end}}

<div class="docs docs--modules">
    <div class="docs__wrap-title">
        <h1 class="docs__title">{{ .Title }}</h1>
    </div>

    <div class="post-content">

        {{- if eq $d8Edition "ee" }}
          {{- partial "alert" ( dict "level" "warn" "content" (T "module_is_available_in_ee_only") ) }}
        {{- end }}
        {{- if eq $moduleStatus "experimental" }}
          {{- partial "alert" ( dict "level" "warn" "content" (T "module_alert_experimental") ) }}
        {{- end }}

        {{.Content}}

        {{- if and .IsPage ( or (eq .File.ContentBaseName "CRD") (eq .File.ContentBaseName "CR") (eq .File.ContentBaseName "CONFIGURATION") ) }} {{/* Render module CRDs */}}

          {{- $_pathElements := index ( findRESubmatch  `^modules/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/*$` .File.Dir 1 ) 0 }}

          {{- $moduleName := index $_pathElements 1 }}
          {{- $moduleChannel := index $_pathElements 2 }}
          {{- if and $moduleName $moduleChannel }}
            {{- $moduleData := index .Site.Data.modules $moduleName }}

            {{- if and ( reflect.IsMap $moduleData ) (index $moduleData $moduleChannel) }}
              {{- $type := "" }}
              {{- if or (eq .File.ContentBaseName "CRD") (eq .File.ContentBaseName "CR")  }} {{/* Render module CRDs */}}
                {{- $type = "crds" }}
              {{- else if eq .File.ContentBaseName "CONFIGURATION" }} {{/* Render module configuration JSONschema */}}
                {{- $type = "configuration" }}
              {{- end }}
              {{- partial "module-resources" (dict "name" $moduleName "data" (index $moduleData $moduleChannel) "type" $type "lang" .Language.Lang )}}
            {{- end }}
          {{- end }}

        {{- end }}

    </div>
</div>
{{- end }}
